﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FYP14
{
    public partial class AddDoctor : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    SetExpense(Convert.ToInt32(Request.QueryString["ID"]));
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            Doctor oDoctor = new Doctor();
            oDoctor.Name = txtName.Text;
            oDoctor.Specialization = txtSpecialization.Text;

            if (Request.QueryString["ID"] != null)
            {
                oDoctor.ID = Convert.ToInt32(Request.QueryString["ID"]);
                BAL.UpdateDoctor(oDoctor);
            }
            else
            {
                BAL.SaveDoctor(oDoctor);
            }

            Response.Redirect("ViewDoctors.aspx");
        }

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("ViewDoctors.aspx");
        }

        private void SetExpense(Int32 ID)
        {
            DataTable dt = BAL.GetDoctor(ID);
            if (dt.Rows.Count > 0)
            {
                txtName.Text = dt.Rows[0]["Name"].ToString();
                txtSpecialization.Text = dt.Rows[0]["Specialization"].ToString();
            }
        }
    }
}